{include file="public/toper" /}
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">运营中心</a>
        <a href="">优惠券详情</a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <input type="text" name="sreach" value=""  style="width:250px;" id="key"   placeholder="会员券名称/用户" autocomplete="off" class="layui-input">
            <div class="layui-input-inline">
                <select name="coupons_type" id="coupons_type">
                    <option value=".">全部</option>
                    <option value="1">满减</option>
                    <option value="2">折扣</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="state" id="state">
                    <option value=".">全部</option>
                    <option value="0">未使用</option>
                    <option value="1">已使用</option>
                    <option value="2">已过期</option>
                </select>
            </div>
            <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <xblock class="demoTable">
        <span class="layui-btn" ><a href="{:url('Coupons/index')}" style="color: #fff">优惠券列表</a></span>
    </xblock>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="sj">
    {{#  if(d.card_order!=''){ }}
    {{layui.util.toDateString(d.card_order.add_time*1000) }}
    {{#  } else if(d.order!='') { }}
    {{layui.util.toDateString(d.order.add_time*1000) }}
    {{#  } }}
</script>
<script type="text/html" id="order">
    {{#  if(d.card_order!=''){ }}
    <div><a href="#"  onclick="x_admin_show('查看订单','{:url(\'Corder/edit\')}?id={{d.card_order.card_order_id}}')" title="查看详情" class="layui-table-link">{{d.card_order.card_order_sn}}</a></div>
    {{#  } else if(d.order!='') { }}
    <div><a href="#"  onclick="x_admin_show('查看订单','{:url(\'Order/order_details\')}?id={{d.order.order_id}}')" title="查看详情" class="layui-table-link">{{d.order.order_sn}}</a></div>
    {{#  } }}
</script>
<script type="text/html" id="time">
    {{layui.util.toDateString(d.settlement_time*1000,"yyyy-MM-dd") }}
</script>
<script>
    layui.use(['table','util'], function(){
        var table = layui.table, $ = layui.jquery;
        var layer = layui.layer;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Coupons/index2')}"
            ,id:'test'
            ,cols: [[
                {field:'coupons_id', width:80, title: '序号',align: 'center',type:'numbers'}
                ,{field:'name',width: 150,title: '名称', align: 'center'}
                ,{field:'coupons_type', width:100, title: '类型',align: 'center',templet: function(d){if(d.coupons_type==1){return '满减';}else if(d.coupons_type==2){ return '折扣';}}}
                ,{field:'scope', width:140, title: '适用范围',align: 'center'}
                ,{field:'conditions',width: 100,title: '满足金额', align: 'center'}
                ,{width: 150,title: '有效期截止', align: 'center', toolbar: '#time'}
                ,{field:'number',width: 100,title: '发行数', align: 'center'}
                ,{field:'uname',width: 100,title: '领取人', align: 'center'}
                ,{field: 'receive_time',width: 180, sort:'true', align: 'center',title: '领取时间', templet: '<div>{{layui.util.toDateString(d.receive_time*1000) }}</div>'}
                ,{field:'state', width:100, title: '状态',align: 'center',templet: function(d){if(d.state==0){return '未使用';}else if(d.state==1){return '已使用';}else if(d.state==2){return '已过期';}}}
                ,{width: 180,title: '使用时间', align: 'center', sort:'true',toolbar: '#sj'}
                ,{width: 180,title: '关联订单', align: 'center', toolbar: '#order'}
            ]]
            ,page: true
            ,limit: 30
            ,limits:[30,60,90,120,150,180,210,240,270,300]
        });
        layer.close(loading);


        $('#search').on('click', function () {
            tableIn.reload({
                where: {key: $('#key').val(),coupons_type:$('#coupons_type').val(),state:$('#state').val()}
                ,page: {curr: 1 }
            });
        });
    });
</script>
{include file="public/footer"/}